package com.moli.iov.down.command.disruptor;

import com.moli.iov.disruptor.DataEvent;
import com.moli.iov.disruptor.DataEventHandler;
import com.moli.iov.down.model.dto.remoting.CommandDto;
import com.moli.iov.down.command.SendCommandService;
import com.moli.iov.util.SpringContextUtils;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p>
 *
 *   Disruptor 消费者
 *
 *   发送命令
 *
 * </p>
 *
 * @author: zql
 * @Date: 2019/1/3 9:41
 */
public class DisruptorConsumer extends DataEventHandler<List<CommandDto>> {

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public void close() throws Exception {
        log.info("关闭消费者");
    }

    @Override
    public void onEvent(DataEvent<List<CommandDto>> event) throws Exception {
        try{
            SendCommandService sendCommandService = SpringContextUtils.getBean("sendCommandService");

            for(CommandDto commandDto : event.getValue()){

                sendCommandService.sendCommand(commandDto);
            }
        }catch(Exception e){
            log.error("异步处理 发送命令异常", e);
        }
    }
}
